# Receive post information from buidaschedule, make a calendar, and put it in 
# the datastore

import webapp2
from google.appengine.ext import db

import ext
			
	
class MainPage(ext.SlotHandler):
	def post(self):
		self.response.out.write(open('html/header-addUsers.html','r').read())	
		#self.response.out.write('BEGIN<br/>')
		self.response.out.write('<div align="center">')
		#self.response.out.write('Collecting email addresses<br/>')
		
		# Collect the email addresses
		if True: 
			user1 = self.request.get('user1')	
			user2 = self.request.get('user2')
			user3 = self.request.get('user3')
			user4 = self.request.get('user4')
			user5 = self.request.get('user5')
			users = [user1, user2, user3, user4, user5]
		
		for i in range(5):
			if users[i]:
				us = ext.User(email=users[i])
				us.put()
				
		self.response.out.write("<h1>Users Added!</h1>")
		# self.printDb()
		for ac in ext.Account.all():
			self.printAc(ac)
			#self.response.out.write('<br/>')
		
		
		#self.response.out.write('<br/>END')
		self.response.out.write("<h1>Want to add more Users to your calendar?</h1>")
		self.response.out.write("Input User e-mail addresses below:")
		self.response.out.write(open('html/addUsers.html','r').read())
		self.response.out.write('</div>')
		self.response.out.write(open('html/footer-addUsers.html','r').read())
		
app = webapp2.WSGIApplication([('/addUsers', MainPage)],
                              debug=True)